package com.otomotion.research.ants.entities;

import gnu.cajo.invoke.Remote;
import gnu.cajo.utils.ItemServer;

import java.net.UnknownHostException;
import java.rmi.RemoteException;
import java.util.Vector;

import com.otomotion.research.ants.information.Surroundings;
import com.otomotion.research.ants.request.Request;
import com.otomotion.research.ants.Behavior.Behavior;

public class AntBrain {
    /*Document brainData;
    boolean brainReady = false;

    AntBrain()  {
        setType(AntType.SCOUT,"basic");
    }

    void setType(AntType type, String subType) {
        try {
            SAXBuilder saxB = new SAXBuilder();
            brainData = saxB.build("./SingleThreadAnts/joelSrc/ants/src/com/otomotion/research/ants/antFiles/" + type.toString() + "." + subType + ".ant");
            String antDescription = ((Element) XPath.selectSingleNode(brainData,"/Ant/Description")).getValue();
            LOGGER.log("Successfully loaded ant file for ant " + antDescription);
            brainReady = true;
        } catch (Exception e) {
            LOGGER.logln("Could not load " + type + "/" + subType + " ant file");
            LOGGER.log("  :" + e.getMessage());
            brainReady = false;
        }
    }*/

    private Ant host;
    private Vector<Behavior> behaviorList;

    AntBrain(Ant host) {
        this.host = host;
        behaviorList = new Vector<Behavior>();
        //Usually, build from file
    }

    public Request getRequest(Surroundings surrounding) {
        return null;
    }


    /**
     * @param args
     */
    public static void main(String[] args) {

        int port = 9999;
        AntBrain brain = new AntBrain(new Ant());


        try {
            System.out.println("brain going online on port " + port);
            Remote.config(null, port, null, 0);
        }
        catch (UnknownHostException ex) {
            System.out.println("Host is unknown.  Quitting");
            System.exit(-1);
        }
        try {
            ItemServer.bind(brain, "brainServer");
        }
        catch (RemoteException ex) {
            System.out.println("Remote Exception.  ");
            ex.printStackTrace();
        }

    }

}
